import Vue from 'vue'
import Vuex from 'vuex'

import {
  bbsTopicQuery,
  bbsTopicDelete,
  bbsTopicAdd,
  bbsTopicUpdate,
  bbsTopicQueryById,
} from '@/api/bbs/bbsTopic'

Vue.use(Vuex)

const state = {}

const getters = {}

const actions = {
  //话题主表增删改查
  async queryBbsTopic({ commit }, listQuery) {
    let res = await bbsTopicQuery({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async queryBbsTopicById({ commit }, id) {
    let res = await bbsTopicQueryById(id)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async delBbsTopic({ commit }, row) {
    let res = await bbsTopicDelete(row.id)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async addBbsTopic({ commit }, data) {
    let res = await bbsTopicAdd(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async updateBbsTopic({ commit }, data) {
    let res = await bbsTopicUpdate(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
}

const mutations = {}

export default {
  state,
  getters,
  actions,
  mutations,
}
